package com.atguigu.gmall.controller;

import com.atguigu.gmall.model.order.OrderInfo;
import com.atguigu.gmall.order.OrderFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author: 封捷
 * @create-date: 2022/9/13 16:08
 */
@Controller
public class PayController {

    @Autowired
    private OrderFeignClient orderFeignClient;

    @RequestMapping("/pay.html")
    public String toPayPage(
            // 获取请求参数
            @RequestParam("orderId") Long orderId,
            Model model) {

        // 调用远程接口查询 OrderInfo 对象
        OrderInfo orderInfo = orderFeignClient.getOrderInfoById(orderId).getData();

        // 将 OrderInfo 对象存入模型
        model.addAttribute("orderInfo", orderInfo);

        // 返回逻辑视图名称
        return "payment/pay";
    }

    @RequestMapping("/pay/success.html")
    public String toPaySuccessPage() {
        return "payment/success";
    }

}
